package com.lgd.factoryattendance.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lgd.factoryattendance.Bean.ProjectSpinner;
import com.lgd.factoryattendance.R;

import java.util.List;

/**
 * @Author lgd
 * @Date 2024/8/5 10:03
 *   电气编码 下拉框适配器
 */
public class ElectricalCodeAdapter extends BaseAdapter {
    private List<ProjectSpinner> electrialCodeList;
    private Context mContext;
    private LayoutInflater layoutInflater;

    public ElectricalCodeAdapter(List<ProjectSpinner> electrialCodeList, Context context) {
        this.electrialCodeList = electrialCodeList;
        this.mContext = mContext;
        this.layoutInflater = LayoutInflater.from(context);;
    }

    @Override
    public int getCount() {
        return electrialCodeList == null ? 0 : electrialCodeList.size();
    }

    @Override
    public Object getItem(int position) {
        return electrialCodeList == null ? null : electrialCodeList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            convertView = layoutInflater.inflate(R.layout.custom_spinner, parent, false);
            holder = new ViewHolder();
            holder.textView = (TextView) convertView.findViewById(R.id.name);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        ProjectSpinner p = electrialCodeList.get(position);
        holder.textView.setText("");
        return convertView;
    }
    static class ViewHolder {
        TextView textView;
    }
    public void updateData(List<ProjectSpinner> newProjectSpinnerList) {
        this.electrialCodeList = newProjectSpinnerList;
        notifyDataSetChanged(); // 通知适配器数据已更改
    }
}
